import { createSlice, PayloadAction } from '@reduxjs/toolkit';
import { fetchAddFavoritesBallSlice, fetchGetFavoritesBallSlice } from './favorites.actions';



const initialState = {
	favoritesBalls: {},
	loading: false,
	errors: null,
	success: false
};

export const addFavoritesSlice = createSlice({
	name: 'addFavoriteBall',
	initialState,
	reducers: {
	},
	extraReducers: (builder) => {
		builder.addCase(fetchAddFavoritesBallSlice.pending, (state) => {
			state.loading = true;
			state.errors = null;
		});
		builder.addCase(
			fetchAddFavoritesBallSlice.fulfilled,
			(state, action) => {
				state.favoritesBalls = action.payload;
				state.loading = false;
			}
		);
		builder.addCase(fetchAddFavoritesBallSlice.rejected, (state, action) => {
			// state.loading = true;
			state.errors = action.error.message;
		});
		builder.addCase(fetchGetFavoritesBallSlice.pending, (state) => {
			state.loading = true;
			state.errors = null;
		});
		builder.addCase(
			fetchGetFavoritesBallSlice.fulfilled,
			(state, action) => {
				state.favoritesBalls = action.payload;
				state.loading = false;
			}
		);
		builder.addCase(fetchGetFavoritesBallSlice.rejected, (state, action) => {
			// state.loading = true;
			state.errors = action.error.message;
		});
	}
});

export default addFavoritesSlice.reducer;

